using UnityEngine;

namespace NodeCanvas.Actions
{
	[Category("Audio")]
	[AgentType(typeof(Transform))]
	public class PlayAudioAtPosition : ActionTask
	{
		[RequiredField]
		public AudioClip Clip;

		[SliderField(0f, 1f)]
		public float Volume = 1f;

		public bool waitUntilFinish;

		protected override string info
		{
			get
			{
				return "PlayAudio '" + ((!Clip) ? "NULL" : Clip.name) + "'";
			}
		}

		protected override void OnExecute()
		{
			AudioSource.PlayClipAtPoint(Clip, base.agent.transform.position, Volume);
			if (!waitUntilFinish)
			{
				EndAction();
			}
		}

		protected override void OnUpdate()
		{
			if (base.elapsedTime >= Clip.length)
			{
				EndAction();
			}
		}
	}
}
